package com.wac.data.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wac.data.entity.Message;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author beta
 * @since 2023-03-16
 */
public interface MessageMapper extends BaseMapper<Message> {

	//获取某用户消息总列表 时间倒序
	@Select("select message.*,user.name from message,user where receive_id = #{userId} and user.id = message.send_id order by time desc")
	Page<Message> selectByUserId(Page page, String userId);

	//分页查询某用户的消息队列 分类 点赞消息 评论消息 关注消息 时间降序
	@Select("select message.*,user.name from message,user where receive_id = #{userId} and user.id = message.send_id and type = #{type} order by time desc")
	Page<Message> selectByUserIdType(Page page, String userId, String type);

	//获取某用户信息 类型 未读 已读
	@Select("select message.*,user.name from message,user where receive_id = #{userId} and user.id = message.send_id and state = #{state} order by time desc")
	Page<Message> selectByUserState(Page page, String userId, int state);

	//已读
	@Update("update message set message.state = 1 where message.receive_id = #{userId}")
	int hasReadedAll(String userId);
}
